package cn.avalon.feign;

import cn.avalon.domain.User;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @description: UserFeign的托底工厂类
 * @author: Avalon
 * @date: 2022年09月17日 ： 23:32
 * @version: ver1.0
 * @email 709785494@qq.com
 */
@Component
public class UserFeignFallbackFactory implements FallbackFactory<UserFeign> {

    @Override
    public UserFeign create(Throwable throwable) {
        // 1.打印接口错误，方便查找错误
        throwable.printStackTrace();
        return new UserFeign() {
            @Override
            public User findById(Long id) {
                return new User(id, "触发熔断！", "用户服务不可用！");
            }
        };
    }
}
